<?php
/**
* @package   auto_occasion
* @subpackage accueil
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

/**
 * page d'accueil
 *
 */
class FoHomeCtrl extends jController {
    /**
    *
    */
    function index() {

		$NUMERR     = $this->intParam('NUMERR',0) ;
		$idOccasion	= isset($_SESSION['SESS_FO_CURRENT_OCCASION'])?$_SESSION['SESS_FO_CURRENT_OCCASION']:array();
		if( isset($NUMERR) && $NUMERR!=0)
		{
		
			$rep			= $this->getResponse('redirect') ;
			$rep->action	= 'annonce~FoAnnonceGestion:formuleOptions' ;
			$rep->params	= array('NUMERR' => $NUMERR ,'idOccasion'=>$idOccasion ,'err'=>1) ;
		}
		else
		{
			$rep						= $this->getResponse('htmlFo');
			$rep->menusActifs			= frontHtmlResponse::MENU_ACCUEIL ;
			$rep->breadCrumb			= array(frontHtmlResponse::MENU_ACCUEIL) ;
			$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/home.js');
			$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/area.js');
			$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');
			jClasses::inc('commun~common');
			//xml pour le header : title, desc, keywords
			$headerContent				= common::readXml(PATH_XML_ACCUEIL);
			// change le header de la page en cours
			$rep->title					=	isset($headerContent->title)?$headerContent->title:'' ;
			$headerContent->keywords	=	isset($headerContent->keywords)?$headerContent->keywords:'' ;
			$headerContent->desc		=	isset($headerContent->desc)?$headerContent->desc:'' ;
			$keywords					= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
			$description				= "<meta name='Description' content='" . $headerContent->desc. "'>" ;
			$rep->addHeadContent($keywords);
			$rep->addHeadContent($description);
			// ---
			$rep->bodyTpl				= 'accueil~FoHome';
			$rep->body->assignZone('oZoneLienUtile', 'accueil~FoHomeLien');
			$rep->body->assignZone('oZoneAcheterVendre', 'accueil~FoHomeAcheterVendre');
			
			//pubHidden et rightContent
			$paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
			$rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
			
			$rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent');

			//---
			
			$rep->body->assignZone('oZoneAnnonce', 'accueil~FoHomeAnnonce');
			//die('maintenance ....');
			$rep->body->assignZone('oZoneEssai', 'accueil~FoHomeEssai');
			$rep->body->assignZone('oZoneGuide', 'accueil~FoHomeGuide');
			$rep->body->assignZone('oZoneEntreprise', 'accueil~FoHomeEntreprise');
			$rep->body->assignZone('oZoneMarquePopulaire', 'accueil~FoHomeMarquePopulaire');
			$rep->body->assignZone('oZoneEssaiConsulte', 'accueil~FoHomeEssaiConsulte');
		
		}
       
        return $rep;
    }


     /**
     * Get les modeles disponible correspondant à une marque
     *
     * @return
     */
    function ajaxGetModelByMarqueId () {
        
        $iMarqueId = $this->intParam('iMarqueId') ;
        
        jClasses::inc('marqueModele~modeleSrv') ;
        jClasses::inc('essais~essaisSrv') ;
        jClasses::inc('commun~common') ;

        $rep     = $this->getResponse('json') ;
        $modele  = modeleSrv::getAllOrderedModeleByMarqueId($iMarqueId) ;
        $modele2 = essaisSrv::getAllFiches(1, 0, 0, $iMarqueId);

        if (sizeof($modele2)) {
            foreach($modele2 as $mod) {
                $recModele = common::init('ao_modele');
                $mod->ess_zVersion = ($mod->ess_zVersion) ? $mod->ess_zVersion : "";
                $recModele->modele_id       = $mod->ess_iModelId;
                $recModele->modele_marque   = $mod->ess_iMarqueId;
                $recModele->modele_libelle  = $mod->modele_libelle . $mod->ess_zVersion;
                $recModele->modele_ordre    = $mod->modele_ordre;
                $recModele->modele_motCle   = $mod->modele_motCle;
                array_push($modele, $recModele);
            }
        }
        $rep->data = $modele;
        
        return $rep;
    }
     /**
     * Get les modeles disponible correspondant à une marque
     *
     * @return
     */
    function ajaxGetModelByMarqueId_ () {
        $iMarqueId = $this->intParam('iMarqueId') ;
        
        jClasses::inc('marqueModele~modeleSrv') ;
        jClasses::inc('essais~essaisSrv') ;
        jClasses::inc('commun~common') ;
        $oRep			= $this->getResponse('json') ;
        $toModeleReturn	= array();
        $toModele		= essaisSrv::getAllFiches(1, 0, 0, $iMarqueId, true);
		
        if (sizeof($toModele)) {
            foreach($toModele as $oModele) {
				$oModeleReturn					= common::init('ao_modele') ;
                $oModeleReturn->ess_zVersion	= ($oModele->ess_zVersion) ? $oModele->ess_zVersion : "";
                $oModeleReturn->ess_id          = $oModele->ess_id;
                $oModeleReturn->modele_id       = $oModele->ess_iModelId;
                $oModeleReturn->modele_marque   = $oModele->ess_iMarqueId;
                $oModeleReturn->modele_libelle  = $oModele->modele_libelle ." ".$oModele->ess_zVersion ;
                $oModeleReturn->modele_ordre    = $oModele->modele_ordre;
                $oModeleReturn->modele_motCle   = $oModele->modele_motCle;
                array_push($toModeleReturn, $oModeleReturn);
            }
        }
        $oRep->data = $toModeleReturn;
        
        return $oRep;
    }

     /**
     * Récupération de la liste des région/departement 
     * correspondant à un type d'entreprise
     *
     * @return
     */
    function ajaxGetRegion () {
        
        $type = $this->intParam('id') ;

        jClasses::inc('entreprise~entrepriseSrv') ;
        
        $rep    = $this->getResponse('json') ;
        $region = entrepriseSrv::getRegionByType($type) ;
        $rep->data = implode('_', $region);

        return $rep;
    }

    function ajaxGetUrl () {
        $rep  = $this->getResponse('json') ;
        $type = $this->intParam('type') ;
        $dept = $this->stringParam('dept') ;
        $cur = $this->stringParam('cur') ;

        $rep->data = jUrl::get("entreprise~FoEntreprise:index", array("type"=>$type , "cur"=>$cur ));

        return $rep;
    }
    
    /*
     * fonction nettoyage url
     */
    function ajaxCleanUrl () {
        $rep  = $this->getResponse('htmlfragment') ;
        $url = $this->stringParam('url') ;
        $tab = explode('/',$url);
        for($i=0; $i<sizeof($tab); $i++) {
            $tab[$i] = jUrl::escape($tab[$i]);
        }
        $url = implode('-',$tab);
        $url = '/recherche/'.substr($url, 11);
        $rep->addContent($url);

        return $rep;
    }
}

    